﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using DotNetOpenAuth.ApplicationBlock;
using DotNetOpenAuth.OAuth.Messages;
using DotNetOpenAuth.OpenId;
using DotNetOpenAuth.OpenId.Extensions.AttributeExchange;
using DotNetOpenAuth.OpenId.RelyingParty;

using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OAuth.ChannelElements;
using DotNetOpenAuth.OpenId.Extensions.OAuth;
using OpenIdRelyingPartyWebForms;

using System.Diagnostics;
using System.IO;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Linq;

namespace YahooSamples.status
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(State.YahooAccessToken))
            {
                string yql = "select message from social.profile.status where guid=me";
                XDocument result = YahooConsumer.YQL(Global.YahooWebConsumer, State.YahooAccessToken, yql);
                XNamespace n1 = "http://www.yahooapis.com/v1/base.rng";
                XNamespace n2 = "http://social.yahooapis.com/v1/schema.rng";

                this.lstatus.Text = result.Root.Element("results").Element(n2 + "status").Element(n2 + "message").Value;                
            }
            else
            {
                Response.Redirect("~/login/Default.aspx");
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.tstatus.Text))
            {
                string yql = "UPDATE social.profile.status SET status='" + this.tstatus.Text + "' WHERE guid='" + State.UserGUID + "'";
                string result = YahooConsumer.putYQL(Global.YahooWebConsumer, State.YahooAccessToken, yql);

                Response.Redirect("~/status/Default.aspx");
            }
        }
    }
}